﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Code.DAL;

namespace Code.Models
{
    /// <summary>
    /// 支付接口
    /// </summary>
    public enum PayType
    {
        /// <summary>
        /// 易宝
        /// </summary>
        YeePay = 1,
        /// <summary>
        /// 支付宝
        /// </summary>
        AliPay = 2,
        /// <summary>
        /// 财付通
        /// </summary>
        TenPay = 3,

        /// <summary>
        /// 工商银行人工转账
        /// </summary>
        ICBC_Manual,
        /// <summary>
        /// 支付宝人工转账
        /// </summary>
        AliPays_Manual,
        /// <summary>
        /// 财付通人工转账
        /// </summary>
        TenPays_Manual,

    }

    public static class PayTypeEx
    {
        public static string GetName(this PayType type)
        {
            switch (type)
            {
                case PayType.YeePay:
                    return "易宝支付平台";
                case PayType.AliPay:
                    return "支付宝支付平台";
                case PayType.TenPay:
                    return "财付通支付平台";
                case PayType.ICBC_Manual:
                    return "工商银行转账充值";
                case PayType.AliPays_Manual:
                    return "支付宝人工转账充值";
                case PayType.TenPays_Manual:
                    return "财付通人工转账充值";
                default:
                    return type.ToString();
            }
        }
        public static Detail GetDetail(this PayType type)
        {
            switch (type)
            {
                case PayType.YeePay:
                    return new Detail
                    {
                        PayType = type,
                        Name = type.GetName(),
                        Enable = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_YeePay_Enable].ToBool(false),
                        MumberID = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_YeePay_MerhantID].Value,
                        Addr = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_YeePay_ReqUrl].Value
                    };
                case PayType.AliPay:
                    return new Detail
                    {
                        PayType = type,
                        Name = type.GetName(),
                        Enable = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_AliPay_Enable].ToBool(false),
                        Key = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_AliPay_Key].Value,
                        MumberID = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_AliPay_MerhantID].Value,
                        Addr = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_AliPay_ReqUrl].Value,
                        MumberName = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_AliPay_Email].Value

                    };
                case PayType.TenPay:
                    return new Detail
                    {
                        PayType = type,
                        Name = type.GetName(),
                        Enable = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_TenPay_Enable].ToBool(false),
                        Key = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_TenPay_Key].Value,
                        MumberID = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_TenPay_MerhantID].Value,
                        Addr = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_TenPay_ReqUrl].Value,
                        //MumberName = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_TenPays_Manual_MemberName].Value,
                    };
                case PayType.ICBC_Manual:
                    return new Detail
                    {
                        PayType = type,
                        Name = type.GetName(),
                        Enable = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_ICBC_Manual_Enable].ToBool(false),
                        Key = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_ICBC_Manual_MemberID].Value,
                        MumberID = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_ICBC_Manual_MemberName].Value,
                        Addr = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_ICBC_Manual_Memo].Value,
                    };
                case PayType.AliPays_Manual:
                    Detail model = new Detail();
                    model.PayType = type;
                    model.Name = type.GetName();
                    model.Enable=BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_Alipays_Manual_Enable].ToBool(false);
                    model.Key = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_Alipays_Manual_MemberID].Value;
                    model.MumberID = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_Alipays_Manual_MemberName].Value;
                    model.Addr = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_Alipays_Manual_Memo].Value;
                    return model;
                case PayType.TenPays_Manual:
                    return new Detail
                    {
                        PayType = type,
                        Name = type.GetName(),
                        Enable = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_TenPays_Manual_Enable].ToBool(false),
                        Key = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_TenPays_Manual_MemberID].Value,
                        MumberID = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_TenPays_Manual_MemberName].Value,
                        Addr = BLL.CacheManage.OptionSite[Option_Site_Key.Site_Pay_TenPays_Manual_Memo].Value,
                    };
                default:
                    throw new ArgumentOutOfRangeException("type");
            }
        }
    }

    public class Detail
    {
        public PayType PayType { get; set; }
        public string Name { get; set; }
        public bool Enable { get; set; }
        public string MumberID { get; set; }
        public string Addr { get; set; }
        public string Key { get; set; }
        public string MumberName { get; set; }
    }
}
